import 'package:flutter_learn_vi/src/bean/bean_user.dart';
import 'package:flutter_learn_vi/src/common/user_helper.dart';
import 'package:flutter_learn_vi/src/net/dio_utils.dart';
import 'package:get/get.dart';

import '../../../../bean/bean_examine.dart';

class ExaminListController extends GetxController {
  int totalCount = 0;
  int totalPage = 0;
  int currPage = 0;
  int pageSize = 30;
  List<ExamineUserBean> goodsList = [];

  Future<bool> requestGoodsList() async {
    UserBean userBean = UserHelper.getInstance.userBean;
    Map<String, dynamic> map2 = {};
    map2["mineId"] = userBean.mineId;
    map2["userId"] = userBean.userId;
    map2["page"] = currPage;
    map2["size"] = pageSize;
    map2["tableIndex"] = _tableIndex;

    ResponseInfo responseInfo = await DioUtils.instance
        .getRequest(url: HttpHelper.myExaminList, queryParameters: map2);
    goodsList = [];
    isLoading = false;
    if (responseInfo.success) {
      //解析数据
      dynamic data = responseInfo.data;
      totalCount = data["totalCount"] ?? 0;
      totalPage = data["totalPage"] ?? 0;
      currPage = data["currPage"] ?? 0;
      pageSize = data["pageSize"] ?? 0;
      dynamic list = data["list"];
      if (list != null) {
        for (dynamic item in list) {
          ExamineUserBean bean = ExamineUserBean.fromMap(item);
          goodsList.add(bean);
        }
      }
    }
    update(["examinList"]);
    return true;
  }

  int _tableIndex = 0;
  bool isLoading = true;

  Future<bool> onPullRefresh() async {
    await Future.delayed(Duration(milliseconds: 200));
    await requestGoodsList();
    return true;
  }

  Future<bool> onRefresh({int index = 0}) async {
    _tableIndex = index;
    isLoading = true;
    update(["examinList"]);
    await requestGoodsList();
    return true;
  }

  @override
  void onReady() {
    super.onReady();

    requestGoodsList();
  }

  void goShop(ExamineUserBean item) async {}
}
